
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><?php echo $title;?></title>
    <!-- 设置缩放 -->
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
    <meta name="format-detection" content="telephone=no" />
    <!-- windows phone 点击无高光 -->
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- icon -->
    <link rel="shortcut icon" href="<?php echo ADMIN_ICO_PIC;?>" type="image/x-icon"/>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="<?php echo SYS_LINK;?>admin/css/content.css?v=<?php echo V_CSSJS;?>" />

    <style>
        .search_box{padding:10px 0 10px 0;}
        .search_box input,.search_box select{width:200px;height:25px;border:1px solid #ddd;padding:0 10px;margin-bottom: 10px;}
        .search_box select{width:100px;height:27px;}
        .search_box .datetime{width:80px;}
        .displayNone{display: none;}
    </style>
</head>
<?php
$userLevel = getUserLevel();
$mouldCode = isset($mouldCode) ? $mouldCode : '';
$menu_id = isset($menu_id) ? $menu_id : 0;
$fid = isset($fid) ? $fid : 0;
$essayListUrl = SYS_URL_PATH("admin_user/m/$mouldCode/c/$menu_id/f/$fid");
$essayAddUrl = SYS_URL_PATH("admin_user_add/m/$mouldCode/c/$menu_id/f/$fid");
$fieldFileType = isset($fieldFileType) ? $fieldFileType : array();
$fieldPicType = isset($fieldPicType) ? $fieldPicType : array();
$fieldBtnType = isset($fieldBtnType) ? $fieldBtnType : array();
$powerInfo = isset($powerInfo) ? $powerInfo : powerInfoListDeVal();
?>
<body>
    <div class="con_box">
        <div class="lab_box2" >
            <a href="<?php echo $essayListUrl;?>" class="lab_base2 act">用户列表<span class="lab_act2"></span></a>
            <?php
            if(in_array('admin_user_add',$powerInfo['classfun']) || $userLevel == 1){
                echo '<a href="javascript:;" class="lab_base2 add_essay_btn" data-url="'.$essayAddUrl.'">+添加用户</a>'.PHP_EOL;
            }
            ?>
        </div>
        <?php
        $search_title = isset($searchInfo['locate']['a.title']) ? $searchInfo['locate']['a.title'] : '';
        $search_status = isset($searchInfo['where']['a.status']) ? $searchInfo['where']['a.status'] : '';
        $search_startdate = isset($searchInfo['gts']['a.createdate']) ? $searchInfo['gts']['a.createdate'] : '';
        $search_enddate = isset($searchInfo['lts']['a.createdate']) ? $searchInfo['lts']['a.createdate'] : '';
        ?>
        <div class="search_box">
            <input type="text" id="search_word" value="<?php echo $search_title;?>" placeholder="请输入用户名关键词">
            <select id="search_status">
                <option value="">请选状态</option>
                <?php
                if(isset($statusList) && !empty($statusList)){
                    foreach($statusList as $k=>$v){
                        $search_status_de = $search_status == $k ? 'selected="selected"' : '';
                        echo '<option value="'.$k.'" '.$search_status_de.'>'.$v.'</option>';
                    }
                }
                ?>
            </select>
            <input type="text" id="date_start" class="datetime" value="<?php echo $search_startdate;?>" placeholder="起始日期">
            ~
            <input type="text" id="date_end" class="datetime" value="<?php echo $search_enddate;?>" placeholder="终止日期">
            &nbsp; &nbsp;
            <button class="btn_base btn_back_sides btn_height25" id="search_btn">搜索</button> &nbsp; &nbsp;
            <?php
            $execlDisplayNone = in_array('admin_user_execl', $powerInfo['classfun']) || $userLevel == 1 ? '' : 'displayNone';
            ?>
            <button class="btn_base btn_back_greens2 btn_height25 <?php echo $execlDisplayNone;?>" id="download_execlbtn">导出</button>
        </div>
        <table class="table_th_td" id="table_list" >
            <tr class="weight400">
                <th width="42"><input type="checkbox" class="checkbox_all"></th>
                <th width="50">排序</th>
                <th width="60">ID</th>
                <th>帐号</th>
                <th width="50">头像</th>
                <th>手机</th>
                <th>邮箱</th>
                <?php
                // 追加字段列
                $fieldCount = 0;
                if(isset($fields) && !empty($fields)){
                    foreach($fields as $k=>$v){
                        if($v['showflag'] == '2'){
                            $fieldCount++;
                            $tdwidth = isset($v['tdwidth']) && $v['tdwidth'] ? 'width="'.$v['tdwidth'].'"' : '';
                            echo '<th '.$tdwidth.'>'.$v['fieldname'].'</th>';
                        }
                    }
                }
                ?>
                <!--<th width="150">时间</th>-->
                <th width="120">状态</th>
                <th width="200">操作</th>
            </tr>
            <?php
            if(isset($list) && !empty($list)){
                foreach($list as $k=>$v){
                    $id = $v['id'];$fid = $v['fid'] ? $v['fid'] : 0;$title = $v['title'];
                    $viewseq = intval($v['viewseq']);$statustxt = $v['statustxt'];
                    $createDate = $v['createdate'];
                    $headimg = $v['headimg'] ? SYS_LINK.$v['headimg'] : ADMIN_HEAD_PIC;
                    $headimg = '<img src="'.$headimg.'" img_src="'.$headimg.'" class="show_pic_btn" width="20px" height="20px">';
                    $phone = $v['mobile'];
                    $email = $v['email'];
                    $updateUrl = SYS_URL_PATH("admin_user_update/m/$mouldCode/c/$menu_id/f/$fid/i/$id");
                    $delUrl = SYS_URL_PATH("admin_user_del/m/$mouldCode/c/$menu_id/i/$id");
                    // 追加插入的字段
                    $trTdInfoAdd = '';
                    if (isset($fields) && !empty($fields)) {
                        foreach ($fields as $fk => $fv) {
                            $fieldcode = isset($fv['fieldcode']) ? $fv['fieldcode'] : '';
                            $txtInfo = isset($v[$fieldcode]) && $fieldcode ? $v[$fieldcode] : '';
                            // 为图片类型时
                            if(in_array($fv['fieldtype'], $fieldPicType)){
                                $txtInfo = '<img src="'.SYS_LINK.$txtInfo.'" img_src="'.SYS_LINK.$txtInfo.'" class="show_pic_btn" width="20px" height="20px">';
                            }
                            // 为文件类型时
                            if(in_array($fv['fieldtype'], $fieldFileType)){
                                $fileIcon = SYS_LINK.'admin/img/common/file.png';
                                $txtInfoStrArr = $txtInfo ? explode('/', $txtInfo) : array();
                                $txtName = end($txtInfoStrArr);
                                $txtInfo = '<img src="'.$fileIcon.'" data-url="'.SYS_LINK.$txtInfo.'" data-name="'.$txtName.'" class="show_file_btn" width="20px" height="20px">';
                            }
                            // 为文章属性时
                            if(in_array($fv['fieldtype'], $fieldBtnType)){
                                $essayAttrUrl = SYS_URL_PATH("admin_user_elementList/m/$mouldCode/i/$id/f/$fieldcode/p/1");
                                $txtInfo = '<a href="javascript:;" data-url="'.$essayAttrUrl.'" class="btn_base btn_line_none essay_attr_btn">查看</a>';
                            }
                            if ($fv['showflag'] == '2') {
                                $trTdInfoAdd .= '<td class="center">' . $txtInfo . '</td>'.PHP_EOL;
                            }
                        }
                    }
                    $updateDisplayNone = in_array('admin_user_update', $powerInfo['classfun']) || $userLevel == 1 ? '' : 'displayNone';
                    $delDisplayNone = in_array('admin_user_del', $powerInfo['classfun']) || $userLevel == 1 ? '' : 'displayNone';
                    echo <<<html
            <tr>
                <td class="center"><input type="checkbox" class="checkbox_no" name="id[]" value="$id"></td>
                <td class="center"><input type="text" class="viewseq" data-id="$id" value="$viewseq"></td>
                
                <td class="center">$id</td>
                <td class="">$title</td>
                <td class="center">$headimg</td>
                <td class="center">$phone</td>
                <td class="">$email</td>
                $trTdInfoAdd
                <!--<td class="center">$createDate</td>-->
                <td class="center">$statustxt</td>
                <td class="center">
                    <a href="javascript:;" data-url="$updateUrl" class="btn_base btn_line_none essay_update_btn $updateDisplayNone">编辑</a>
                    <a href="javascript:;" data-url="$delUrl" class="btn_base btn_line_none essay_del_btn $delDisplayNone">删除</a>
                </td>
            </tr>
html;

                }
            }
            ?>

            <tr class="operates_box">
                <td class="center">
                    <!--<button class="btn_base btn_height20 btn_line_none" id="delall_btn" title="批量删除">Del</button>-->
                </td>
                <td class="center">
                    <?php
                    $seqDisplayNone = in_array('admin_user_seq', $powerInfo['classfun']) || $userLevel == 1 ? '' : 'displayNone';
                    ?>
                    <button class="btn_base btn_height20 btn_line_none <?php echo $seqDisplayNone?>" id="viewseq_btn" data-url="<?php echo SYS_URL_PATH("admin_user_seq/m/$mouldCode");?>" title="提交排序">↓↑</button>
                </td>
                <td class="center">
                    <!-- 选中的下载Execl -->

                    <button class="btn_base btn_height20 btn_line_none btn_lineheight25 <?php echo $execlDisplayNone;?>" id="down_execl_btn" title="下载Execl"></button>
                </td>
                <td colspan="<?php echo $fieldCount+4;?>" class="center"></td>
                <td class="center">
                    <?php
                    // 选中的批量修改状态
                    if($userLevel == 1){
                        echo '<select class="select selectw50" id="newStatus">';
                        echo '<option value="1">待审</option>';
                        echo '<option value="2">已审</option>';
                        echo '<option value="3">关闭</option>';
                        echo '</select>'.PHP_EOL;
                        echo '<button class="btn_base btn_height20" id="status_btn" title="批量修改">操作</button>';
                    }
                    ?>
                </td>
                <td>
                    <?php
                    // 选中的转移到其他导航栏目下
                    if($userLevel == 1 && 0){
                        echo '<select class="select selectw120" id="newClassId">';
                        echo '<option value="">请选择</option>';
                        if(isset($classMeet)){
                            foreach($classMeet as $v){
                                $level = $v['level']*2;
                                $str = str_pad("",$level, '-',STR_PAD_LEFT );
                                echo '<option value="'.$v['id'].'">'.$str.' '.$v['classname'].'</option>';
                            }
                        }
                        echo '</select>'.PHP_EOL;
                        echo '<button class="btn_base btn_height20" id="move_btn">移动</button>';
                    }
                    ?>
                </td>
            </tr>
        </table>
        <?php
        $pageNo = isset($pages["pageNo"]) ? intval($pages["pageNo"]) : 1;
        $pageSum = isset($pages["pageSum"]) ? intval($pages["pageSum"]) : 1;
        $counts = isset($pages["counts"]) ? intval($pages["counts"]) : 0;
        ?>
        <div class="page_box">
            <i class="page_start">首页</i>
            <i class="page_prev">上一页</i>
            <input type="number" class="page_no" value="<?php echo $pageNo;?>"> /
            <span class="page_sum"><?php echo $pageSum;?></span>
            <i class="page_next">下一页</i>
            <i class="page_end">尾页</i>
            <span class="page_list">共 <b><?php echo $counts;?> </b>条记录</span>
        </div>
    </div>
</body>
<script language="javascript">
    var http_url = '<?php echo SYS_HOST;?>';
    var http_link = '<?php echo SYS_LINK;?>';
    var cssjsv = '<?php echo V_CSSJS;?>';
    var http_fix = '<?php echo SYS_URL_FIX;?>';
    var mouldCode = '<?php echo $mouldCode;?>';
    var menu_id = '<?php echo $menu_id;?>';
    var pageNo = '<?php echo $pageNo;?>';
    var pageSum = '<?php echo $pageSum;?>';
    var essayUrl = '<?php echo "admin_user_index/m/$mouldCode/c/$menu_id/f/$fid";?>';
    var downExeclUrl = '<?php echo SYS_URL_PATH("admin_user_execl/m/$mouldCode/c/$menu_id/f/$fid/o/a.id_asc");?>';
    var delMoreUrl = '<?php echo SYS_URL_PATH("admin_user_dels");?>';
    var moveUrl = '<?php echo SYS_URL_PATH("admin_user_move");?>';
    var statusUrl = '<?php echo SYS_URL_PATH("admin_user_status");?>';

</script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/jquery.min.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/skin.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/common.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript">file_load('list');</script>
<script language="javascript">
    var nowDate = '<?php echo date("Y-m-d");?>';
    window.onload = function () {
        var viewer = new Viewer(document.getElementById('table_list'), {
            url: 'data-src'
        });
        // 日期
        jeDate({
            dateCell: '#date_start',
            isTime: false,
            format: 'YYYY-MM-DD',
            minDate: '2022-06-01',
            maxDate:nowDate
        })

        // 日期
        jeDate({
            dateCell: '#date_end',
            isTime: false,
            format: 'YYYY-MM-DD',
            minDate: '2022-06-01',
            maxDate:nowDate
        })
    }
    // 获取ckeckbox选中的值
    function getCheckedVal(){
        let chk_value =[];
        $('.checkbox_no:checked').each(function(){
            chk_value.push($(this).val());
        });
        var selectId = chk_value.join(",");
        console.log(selectId);
        return selectId;

    }

    // 全选
    $('.checkbox_all').click(function(){
        let checkboxFlag = $('.checkbox_all').prop('checked');
        if(checkboxFlag){
            $('.checkbox_no').attr('checked','checked');
            getCheckedVal();
        }else{
            $('.checkbox_no').removeAttr('checked');
        }
    })

    ////////////////////////////////////////////

    // 下载文件 / 预览文件
    $('.show_file_btn').click(function(){
        let goutoURL = $(this).attr('data-url');
        let fileName = $(this).attr('data-name');
        downloadFile(goutoURL, fileName);
    });

    //文章属性列表
    $('.essay_attr_btn').click(function(){
        let goutoURL = $(this).attr('data-url');
        if(!goutoURL){
            layer.msg('网络异常');
        }else{
            layerIframe(goutoURL, '90%', '90%', 1);
        }
    });

    //添加文章
    $('.add_essay_btn').click(function(){
        let goutoURL = $(this).attr('data-url');
        if(!goutoURL){
            layer.msg('网络异常');
        }else{
            layerIframe(goutoURL, '90%', '90%', 1);
        }
    });

    //修改文章
    $('.essay_update_btn').click(function(){
        let goutoURL = $(this).attr('data-url');
        if(!goutoURL){
            layer.msg('网络异常');
        }else{
            layerIframe(goutoURL, '90%', '90%', 1);
        }
    });

    //删除
    $('.essay_del_btn').click(function(){
        let goutoURL = $(this).attr('data-url');
        if(!goutoURL){
            layer.msg('网络异常');
        }else{
            layer.confirm('确定删除？', {
                btn: ['确定','取消']
            }, function(){
                $.post(goutoURL, {subFlag:'Y'}, function(data){
                    if(data=='Y'){
                        layer.msg('删除成功');
                        setTimeout(function(){
                            window.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },'json');
            }, function(){ });
        }
    })

    // 批量删除
    $('#delall_btn').click(function(){
        let idStr = getCheckedVal();
        if(!idStr){
            layer.msg('请先选中');
        }else{
            layer.confirm('确定删除选中的？', {
                btn: ['确定','取消']
            }, function(){
                $.post(delMoreUrl, {m:mouldCode,c:menu_id,i:idStr,}, function(data){
                    if(data=='Y'){
                        layer.msg('删除成功');
                        setTimeout(function(){
                            window.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },'json');
            }, function(){ });
        }
    });

    // 批量下载
    $('#down_execl_btn').click(function(){
        let idStr = getCheckedVal();
        if(!idStr){
            layer.msg('请先选中');
        }else{
            var confirmlayer = layer.confirm('确定导出选中的数据？', {
                btn: ['确定','取消']
            }, function(){
                layer.close(confirmlayer);// 关闭加载层
                jspost(downExeclUrl, {i:idStr});
            }, function(){ });
        }
    });

    // 批量移动moveUrl
    $('#move_btn').click(function(){
        let idStr = getCheckedVal();
        let newClassId = $('#newClassId').val();
        if(!idStr || !newClassId){
            layer.msg('请先选中');
        }else{
            layer.confirm('确定移动选中的？', {
                btn: ['确定','取消']
            }, function(){
                $.post(moveUrl, {m:mouldCode,c:menu_id,i:idStr,c2:newClassId}, function(data){
                    if(data=='Y'){
                        layer.msg('操作成功');
                        setTimeout(function(){
                            window.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },'json');
            }, function(){ });
        }
    });

    // 批量修改状态
    $('#status_btn').click(function(){
        let idStr = getCheckedVal();
        let newStatus = $('#newStatus').val();
        if(!idStr || !newStatus){
            layer.msg('请先选中');
        }else{
            layer.confirm('确定修改选中的？', {
                btn: ['确定','取消']
            }, function(){
                $.post(statusUrl, {m:mouldCode,c:menu_id,i:idStr,s:newStatus}, function(data){
                    if(data=='Y'){
                        layer.msg('操作成功');
                        setTimeout(function(){
                            window.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },'json');
            }, function(){ });
        }
    });

    // 列表
    function listGoTo(listUrl){
        let search = {};
        search.search_title = $('#search_word').val();
        search.search_status = $('#search_status').val();
        search.search_startdate = $('#date_start').val();
        search.search_enddate = $('#date_end').val();
        let dataJson = JSON.stringify(search);
        jspost(http_url+listUrl+http_fix, {search:dataJson});
    }

    //分页-首页
    $('.page_start').click(function(){
        let listUrl = essayUrl+'/p/1';
        listGoTo(listUrl);
    });

    //分页-尾页
    $('.page_end').click(function(){
        let listUrl = essayUrl+'/p/'+pageSum;
        listGoTo(listUrl);
    });

    //分页-上一页
    $('.page_prev').click(function(){
        let prevPage = parseInt(pageNo)-1 > 1 ? parseInt(parseInt(pageNo)-1) : 1;
        let listUrl = essayUrl+'/p/'+prevPage;
        listGoTo(listUrl);
    });

    //分页-下一页
    $('.page_next').click(function(){
        let nextPage = parseInt(parseInt(pageNo)+1) > pageSum ? pageSum : parseInt(parseInt(pageNo)+1);
        let listUrl = essayUrl+'/p/'+nextPage;
        listGoTo(listUrl);
    });

    //分页-跳页
    $('.page_no').blur(function(){
        let page_no = $('.page_no').val();
        let listUrl = essayUrl+'/p/'+page_no;
        listGoTo(listUrl);
    });

    // 导出execl
    $('#download_execlbtn').click(function(){
        window.location.href = downExeclUrl;
    });

    // 查询
    $('#search_btn').click(function(){
        listGoTo(essayUrl);
    });


</script>
</html>